$(function () {
  //加载数据
  var $tbServer = $('#tbServer'), $pager = $('#tbServerPager');
  $tbServer.jqGrid({
    url: indexServer_urls.getWork,
    datatype: 'json',
    mttype: 'post',
    colNames: ['工单号', '车牌号', '接待人','维修技师','操作'],
    colModel: [
      {name: 'num', index: 'num', width: '100', align: 'center'},
      {name: 'car_num', index: 'car_num', width: '100', align: 'center'},
      // {name: 'client_name', index: 'client_name', width: '100', align: 'center'},
      {name: 'reception_name', index: 'reception_name', width: '100', align: 'center'},
      {name: 'repairman_name', index: 'repairman_name', width: '100', align: 'center'},
      {
        name: 'id', index: 'id', width: '100', align: 'center',
        formatter: function (value, options, obj) {
          return '<a style="cursor:pointer;" onclick="indexServer.serverItems('+value+');">服务项目</a>';
        }
      },
    ],
    height: 'auto',
    pager: '#tbServerPager',
    viewrecords: true,
    rowNum: 10,
    rowList: [10, 20, 40],
    autowidth: true
  });
  // 隐藏水平方向滚动
  $tbServer.closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });


  $('#tbServerItem').jqGrid({
    url: '/admin/server/getServerItems/id/0',
    datatype: 'json',
    mttype: 'post',
    colNames: ['名称', '数量','单价', '小计'],
    colModel: [
      {name: 'name', index: 'name', width: '110', align: 'center'},
      {name: 'num', index: 'num', width: '110', align: 'center'},
      // {name: 'client_name', index: 'client_name', width: '100', align: 'center'},
      {name: 'price', index: 'price', width: '150', align: 'center'},
      {name: 'price', index: 'price', width: '160', align: 'center',formatter:function(value,options,obj){
        return value*obj.num;
      }},
    ],
    height: 'auto',
    pager: '#tbServerItemPager',
    // viewrecords: true,
    rowNum: 10,
    rowList: [10, 20, 40],
    autowidth: true
  });
  // 隐藏水平方向滚动
  $('#tbServerItem').closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
});
indexServer = {
  search: function () {
    var $fmQuery = $('.fmWorkServer-hook');
    var param = ittaoli.serializeObject($fmQuery);
    $('#tbServer').jqGrid('setGridParam', {
      postData: {q: JSON.stringify(param)},
      page: 1
    }).trigger("reloadGrid");
  },
  searchNull: function () {
    $('.fmWorkServer-hook input').val('');
    var param = {};
    $('#tbServer').jqGrid('setGridParam', {
      postData: {q: JSON.stringify(param)},
      page: 1
    }).trigger("reloadGrid");
  },

  serverItems:function(id){
    $('#tbServerItem').jqGrid('setGridParam',{
      url:'/admin/server/getServerItems/id/'+id
    }).trigger("reloadGrid");
    $('#modal-tbServer').modal('show');
  }
};